#include "OptionsMenuScreen.h"
#include <iostream>

OptionsMenuScreen::OptionsMenuScreen() {
}


OptionsMenuScreen::~OptionsMenuScreen() {
}







void OptionsMenuScreen::Initialize(sf::RenderWindow* window) {
	m_renderWindow = window;

	OptionsTexture.loadFromFile("bilder/Options/options.png");
	OptionsSprite.setTexture(OptionsTexture);

	BackTexture.loadFromFile("bilder/Options/back.png");
	BackSprite.setTexture(BackTexture);

	SliderTexture.loadFromFile("bilder/Options/sliderball.png");
	FullscreenTexture.loadFromFile("bilder/Options/fullscreen.png");
	WindowTexture.loadFromFile("bilder/Options/Window.png");

	MusicSprite.setTexture(SliderTexture);
	MusicSprite.setOrigin(SliderTexture.getSize().x/2,SliderTexture.getSize().y/2);
	MusicSprite.setPosition(1000, 376);
	VoiceSprite.setTexture(SliderTexture);
	VoiceSprite.setOrigin(SliderTexture.getSize().x/2,SliderTexture.getSize().y/2);
	VoiceSprite.setPosition(1000, 478);
	SFXSprite.setTexture(SliderTexture);
	SFXSprite.setOrigin(SliderTexture.getSize().x/2,SliderTexture.getSize().y/2);
	SFXSprite.setPosition(1000,581);

	BackTexture.loadFromFile("bilder/Options/back.png");
	BackSprite.setTexture(BackTexture);
	BackSprite.setOrigin(BackTexture.getSize().x/4,BackTexture.getSize().y/2);
	BackSprite.setPosition(1145,  675);


	FullscreenSprite.setTexture(FullscreenTexture);
	FullscreenSprite.setOrigin(FullscreenTexture.getSize().x/4, FullscreenTexture.getSize().y/2);
	FullscreenSprite.setPosition(396,376);
	WindowSprite.setTexture(WindowTexture);
	WindowSprite.setOrigin(WindowTexture.getSize().x/4, WindowTexture.getSize().y/2);
	WindowSprite.setPosition(396, 478);

	isFullscreen = false;
	fromMainMenu = false;

	TestSoundBuffer.loadFromFile("sounds/testSound.wav");
	TestSound.setBuffer(TestSoundBuffer);


}

void OptionsMenuScreen::Update(sf::Vector2i mousePos, sf::RenderWindow* window, sf::VideoMode* vidMode) {
	m_mousePos = mousePos;
	m_renderWindow = window;
	m_vidMode = vidMode;



	m_MusicVolume = MusicSprite.getPosition().x - 766;
	m_VoiceVolume = VoiceSprite.getPosition().x - 766;
	m_SFXVolume = SFXSprite.getPosition().x - 766;


	//std::cout << m_MusicVolume << std::endl;

	if (m_mousePos.x >765 && m_mousePos.x < 1014 && m_mousePos.y >341 && m_mousePos.y < 426 && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		MusicSprite.setPosition(m_mousePos.x, 376);
	}
	if (MusicSprite.getPosition().x > 1013) {
		MusicSprite.setPosition(1013, 376);
	}
	if (MusicSprite.getPosition().x < 765) {
		MusicSprite.setPosition(766, 376);
	}



	if (m_mousePos.x >765 && m_mousePos.x <= 1100 && m_mousePos.y >457 && m_mousePos.y < 523 && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		VoiceSprite.setPosition(m_mousePos.x, 478);
		TestSound.setVolume(m_VoiceVolume);
		if (TestSound.getStatus() != TestSound.Playing) {
			TestSound.play();
		}
	}
	if (VoiceSprite.getPosition().x >= 1014) {
		VoiceSprite.setPosition(1013, 478);
	}
	if (VoiceSprite.getPosition().x < 766) {
		VoiceSprite.setPosition(766, 478);
	}


	
	if (m_mousePos.x >765 && m_mousePos.x < 1100 && m_mousePos.y >546 && m_mousePos.y < 616 && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		SFXSprite.setPosition(m_mousePos.x, 581);
		TestSound.setVolume(m_SFXVolume);
		if (TestSound.getStatus() != TestSound.Playing) {
			TestSound.play();
		}
	}
	if (SFXSprite.getPosition().x > 1013) {
		SFXSprite.setPosition(1013, 581);
	}
	if (SFXSprite.getPosition().x < 766) {
		SFXSprite.setPosition(766, 581);
	}
	
	if ((m_mousePos.x > FullscreenSprite.getPosition().x - FullscreenTexture.getSize().x/4 && m_mousePos.x < FullscreenSprite.getPosition().x + FullscreenTexture.getSize().x/4 && m_mousePos.y < FullscreenSprite.getPosition().y + FullscreenTexture.getSize().y && m_mousePos.y > FullscreenSprite.getPosition().y) || isFullscreen == true) {
		FullscreenSprite.setTextureRect(sf::IntRect(197,0,197,45));
		if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && isFullscreen == false) {
			m_renderWindow->close();
			m_renderWindow->create(*m_vidMode, "Dawn", sf::Style::Fullscreen);
			isFullscreen = true;
		}
	} else {
		FullscreenSprite.setTextureRect(sf::IntRect(0,0,197,45));
	}

	if ((m_mousePos.x > WindowSprite.getPosition().x - WindowTexture.getSize().x/4 && m_mousePos.x < WindowSprite.getPosition().x + WindowTexture.getSize().x/4 && m_mousePos.y < WindowSprite.getPosition().y + WindowTexture.getSize().y && m_mousePos.y > WindowSprite.getPosition().y) || isFullscreen == false) {
		WindowSprite.setTextureRect(sf::IntRect(218,0,218,54));
		if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && isFullscreen == true) {
			m_renderWindow->close();
			m_renderWindow->create(*m_vidMode, "Dawn", sf::Style::Close);
			isFullscreen = false;
		}
	} else {
		WindowSprite.setTextureRect(sf::IntRect(0,0,218,54));
	}

	if (m_mousePos.x > 1032 && m_mousePos.x < 1262 && m_mousePos.y < 710 && m_mousePos.y > 638) {
		BackSprite.setTextureRect(sf::IntRect(148,0,148,58));
	}  else {
		BackSprite.setTextureRect(sf::IntRect(0,0,148,58));
	}




	m_renderWindow->draw(OptionsSprite);
	m_renderWindow->draw(MusicSprite);
	m_renderWindow->draw(VoiceSprite);
	m_renderWindow->draw(SFXSprite);
	m_renderWindow->draw(FullscreenSprite);
	m_renderWindow->draw(WindowSprite);
	m_renderWindow->draw(BackSprite);

}

void OptionsMenuScreen::Cleanup() {
}

int OptionsMenuScreen::getMusicVolume() {
	return m_MusicVolume;
}

int OptionsMenuScreen::getVoiceVolume() {
	return m_VoiceVolume;
}


int OptionsMenuScreen::getSFXVolume() {
	return m_SFXVolume;
}